package com.shujia.mr.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 需求：
 *      读取学生总分数据，对学生总分进行排序
 *
 *  当Score类只实现了序列化类，是不能够作为Key写出，因为Map端写出数据时，
 *          需要对Key进行排序，而Score中并没有CompareTo比较函数
 */
public class SortMapper extends Mapper<LongWritable, Text,Score, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Score, NullWritable>.Context context) throws IOException, InterruptedException {
//        1500100001	406
        String[] columns = value.toString().split("\t");
        Score score = new Score(columns[0], columns[1]);
        context.write(score,NullWritable.get());
    }
}
